import socket
import time
# text_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# text_sock.bind((self_ip, text_port))
camera_client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ip = '127.0.0.1'
port = 42000
camera_client.connect((ip, port))

print('[+] Unity端连接成功')
 
while True:
    msg = input('>>>')
    if msg == 'quit':
        break
    if len(msg) == 0:
        continue

    try:
        camera_client.send(msg.encode('utf-8'))
        camera_client.send(msg.encode('utf-8'))
        data = camera_client.recv(1024).decode('utf-8')
    except ConnectionResetError:
        print('远程主机已关闭')
        break

    if not data:
        print('[+]  Server主动断开链接.....')
        break
    else:
        print("[localtime] {0} \t  服务器端消息：{1}".format(
                time.asctime(time.localtime()), data))


print("[+] Client端关闭")
camera_client.close()

        